/*********************************************************
          File Name:12.6.cpp
          Author: Abby Cin
          Mail: abbytsing@gmail.com
          Created Time: Tue 15 Sep 2015 04:38:06 PM CST
**********************************************************/

#include <iostream>
#include <new>          // nothrow
#include <vector>

void getvi(std::vector<int>* &vi)
{
        for(int i = 0; i < 3; i++)
                vi->push_back(i);
}

void putvi(std::vector<int>* &vi)
{
        for(auto &x: *vi)
                std::cout << x << " ";
        std::cout << std::endl;
}

int main()
{
        // `nothrow` force `new` return `nullptr` when failed rather than `throw`
        // an excpetion
        auto vi = new (std::nothrow) std::vector<int>();
        if(vi == nullptr)
        {
                std::cerr << "can't allocate memory\n";
                exit(1);
        }
        getvi(vi);
        putvi(vi);

        delete vi;

        return 0;
}
